import allure
from selenium.webdriver.common.by import By

from automation_ui.base.base import BasePage
from automation_ui.untils.log_util import logger


class CouponPage(BasePage):
    __coupon_title = By.CSS_SELECTOR, '.filter-item>.el-input__inner'
    __select_button = By.CSS_SELECTOR, '.el-icon-search'
    __coupon_list = By.CSS_SELECTOR, '.el-table'
    __select_type = By.CSS_SELECTOR, '[placeholder="请选择优惠券类型"]'
    __select_type1 = By.CSS_SELECTOR, 'body>div.el-select-dropdown ul>li:nth-child(1)'
    __select_type2 = By.CSS_SELECTOR, 'body>div.el-select-dropdown ul>li:nth-child(2)'
    __select_type3 = By.CSS_SELECTOR, 'body>div.el-select-dropdown ul>li:nth-child(3)'
    __select_state = By.CSS_SELECTOR, '[placeholder="请选择优惠券状态"]'
    __select_state1 = By.CSS_SELECTOR, 'body>div.el-select-dropdown ul>li:nth-child(1)'
    __select_state2 = By.CSS_SELECTOR, 'body>div.el-select-dropdown ul>li:nth-child(2)'
    __select_state3 = By.CSS_SELECTOR, 'body>div.el-select-dropdown ul>li:nth-child(3)'

    @allure.step('按优惠卷标题搜索')
    def select_coupon_title(self, myput):
        """
        按优惠卷标题搜索
        :param myput:
        :return:
        """
        self.send_key(self.__coupon_title, key=myput)
        return self

    @allure.step('点击查找')
    def select_button(self):
        """
        查找按钮
        :return:
        """
        self.click(self.__select_button)
        return self

    @allure.step('查看优惠卷列表')
    def coupon_list(self):
        """
        优惠卷列表
        :return:
        """
        res = self.find_ele(self.__coupon_list)
        logger.info('列表表单')
        self.screencap()
        self.source()
        return res

    @allure.step('优惠券类型——通用领卷')
    def select_type1(self):
        """
        通用领卷
        :return:
        """
        self.click(self.__select_type)
        self.click(self.__select_type1)
        return self

    @allure.step('优惠券类型——注册赠券')
    def select_type2(self):
        """
        注册赠券
        :return:
        """
        self.click(self.__select_type)
        self.click(self.__select_type2)
        return self

    @allure.step('优惠券类型——兑换码')
    def select_type3(self):
        """
        兑换码
        :return:
        """
        self.click(self.__select_type)
        self.click(self.__select_type3)
        return self

    @allure.step('优惠券状态——正常')
    def select_state1(self):
        """
        优惠券状态——正常
        :return:
        """
        self.click(self.__select_state)
        self.click(self.__select_state1)
        return self

    @allure.step('优惠券状态——过期')
    def select_state2(self):
        """
        优惠券状态——过期
        :return:
        """
        self.click(self.__select_state)
        self.click(self.__select_state2)
        return self

    @allure.step('优惠券状态——下架')
    def select_state3(self):
        """
        优惠券状态——下架
        :return:
        """
        self.click(self.__select_state)
        self.click(self.__select_state3)
        return self
